package com.easylinkin.linkappapi.meterbilling.controller;

import com.easylinkin.linkappapi.common.model.RequestModel;
import com.easylinkin.linkappapi.meterbilling.entity.RechargeRecord;
import com.easylinkin.linkappapi.meterbilling.service.RechargeRecordService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @program: linkapp-group
 * @description: 充值记录
 * @author: chenkaixuan
 * @create: 2021-07-14 09:22
 */
@RestController
@RequestMapping("/cbjf/rechargeRecord")
public class RechargeRecordController {
    @Autowired
    RechargeRecordService service;

    @PostMapping("page")
    public RestMessage page(@RequestBody RequestModel<RechargeRecord> requestModel){
        Assert.notNull(requestModel, "参数为空");
        Assert.notNull(requestModel.getPage(), "参数page为空");
        Assert.notNull(requestModel.getCustomQueryParams(), "customQueryParams参数为空");
        return  RestBuilders.successBuilder().data(service.getMeterDeviceConfigList(requestModel.getPage(),requestModel.getCustomQueryParams())).build();
    }

    @PostMapping("getMeterDeviceConfigCost")
    @ApiOperation("水电表费用统计")
    public RestMessage getMeterDeviceConfigCost(@RequestBody RechargeRecord rechargeRecord){
        return  RestBuilders.successBuilder().data(service.getMeterDeviceConfigCost(rechargeRecord)).build();
    }

    @PostMapping("exportData")
    @ApiOperation("导出")
    public void exportData(@RequestBody RechargeRecord rechargeRecord, HttpServletRequest request, HttpServletResponse response) {
        service.exportData(rechargeRecord, request, response);
    }
}
